module KELASE
  module_function
  MIN_NUM = 0
  
  MAX_NUM = 10
  
  def random_gift(show = true)
    $game_party.set_temp("rm",MIN_NUM + rand(MAX_NUM - MIN_NUM + 1))
    $game_party.incr_value("trc",1 + rand(2 - 1 + 1))
    container = [$data_items,$data_weapons,$data_armors]
    params = case $game_party.get("rm")
    when 1,2,3 # 能量注射器
      # 0为物品,1为武器,2为防具以下为 物品,108号,1个(个数不填默认1个)
      [0,5,1]
    when 4,5,6,7,8 # 3为金钱,要加的钱数量
      [3,15000]
    when 9,10 # 150mm穿甲炮Ⅳ
      return random_gift(show) if $game_party.get("trc",0) < 8
      $game_party.set_temp("trc",0)
      [2,270,1]
    end
    if params
      if params[0] < 3
        $game_party.gain_item(container[params[0]][params[1]],params[2] || 1)
        show_gain_window(params[0] + 1,params[1],params[2] || 1) if show
      else
        $game_party.gain_gold(params[1])
        show_gain_window(0,0,params[1]) if show
      end
      # temp random count
      $game_party.incr_value("trc")
    end
  end
  def show_gain_window(type,id,value = 0)
    snstar2006_66rpg = Window_Base.new((640-200)/2,(480-94)/2,200,94)
    snstar2006_66rpg.contents = Bitmap.new(snstar2006_66rpg.width - 32, snstar2006_66rpg.height - 32)
    if value >= 0
      gain_text = "获得"    
    else
      gain_text = "失去"
    end
    case type
    when 0
      gain_type = "金钱"
      if value >=0
        Audio.se_play($gain_gold_se,80,100)
      else
        Audio.se_play("Audio/SE/"+"Item1",80,100)
      end
    when 1
      gain_type = "物品"
      string = $data_items[id]
      if value >=0
        Audio.se_play($gain_item_se,80,100)
      else
        Audio.se_play($loss_item_se,80,100)
      end
    when 2
      gain_type = "武器"
      string = $data_weapons[id]
      if value >=0
        Audio.se_play($gain_weapon_se,80,100)
      else
        Audio.se_play($loss_weapon_se,80,100)
      end
    when 3
      gain_type = "装备"
      string = $data_armors[id]
      if value >=0
        Audio.se_play($gain_armor_se,80,100)
      else
        Audio.se_play($loss_armor_se,80,100)
      end
    end
    snstar2006_66rpg.contents.draw_text(0,0,160,30,gain_text+gain_type+"：")
    unless type == 0
      snstar2006_66rpg.draw_item_name(string, 0, 30, true)
      snstar2006_66rpg.contents.draw_text(0, 30, 160, 30, "×"+value.abs.to_s, 2)
    else
      snstar2006_66rpg.draw_icon(224, 20, 30,true)
      snstar2006_66rpg.contents.draw_text(0,30,165,30,value.abs.to_s + "  "+ Vocab.currency_unit, 2)
    end
    snstar2006_66rpg.opacity = 255 ###SR
    for i in 0..50
      Graphics.update
    end
    for i in 0..10
      snstar2006_66rpg.opacity -= 10
      snstar2006_66rpg.contents_opacity -= 10
      Graphics.update
    end
    snstar2006_66rpg.dispose
  end
end
#随机码礼包